package com.gdiss.www.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用返回格式
 * @author yly
 * @date 2021/11/30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultVo<T> {

    private Integer code;
    private String msg;
    private T data;

    /**
     * 构造器私有化
     * 功能描述 请求成功的返回数据
     * @param data 具体数据
     */
    public ResultVo(T data) {
        this.data = data;
        this.code = 200;
        this.msg = "OK";
    }

    /**
     * 构造器私有化
     * 功能描述
     * @param msg  请求错误的响应信息
     * @param code 请求错误的响应码
     */
    public ResultVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }



    /**
     * 参数xxx不能为空
     * @param parameterName 参数名称
     * @return {code:2001 ,mag:参数xxx不能为空}对象
     */
    public ResultVo<T> emptyParamError(String parameterName){
        this.code = 2001;
        this.msg = "参数"+parameterName+"不能为空";
        return this;
    }

    /**
     * 参数xxx格式错误
     * @param parameterName 参数名称
     * @return {code:3000 ,mag:参数xxx格式不合法}对象
     */
    public ResultVo<T> paramNotValid(String parameterName){
        this.code = 3000;
        this.msg = "参数"+parameterName+"格式不合法";
        return this;
    }

}
